#include "node_affiliate.h"

void node_affiliate::setSize(glm::vec2 size)
{
    size_ = size;
    setOffsetByAnchor(anchor_);
}

void node_affiliate::setOffsetByAnchor(Anchor anchor)
{
    anchor_ = anchor;
    switch (anchor_){
        case Anchor::ANCHOR_TOP_LEFT:
            offset_ = {0.0f,0.0f};
            break;
        case Anchor::ANCHOR_TOP_CENTER:
            offset_ = {-size_.x/2.0f,0.0f};
            break;
        case Anchor::ANCHOR_TOP_RIGHT:
            offset_ = {-size_.x,0.0f};
            break;
        case Anchor::ANCHOR_CENTER_LEFT:
            offset_ = {-size_.x/2.0f,-size_.y/2.0f};
            break;
        case Anchor::ANCHOR_CENTER:
            offset_ = {-size_.x/2.0f,-size_.y/2.0f};
            break;
        case Anchor::ANCHOR_CENTER_RIGHT:
            offset_ = {-size_.x,-size_.y/2.0f};
            break;
        case Anchor::ANCHOR_BOTTOM_LEFT:
            offset_ = {0.0f,-size_.y};
            break;
        case Anchor::ANCHOR_BOTTOM_CENTER:
            offset_ = {-size_.x/2.0f,-size_.y};
            break;
        case Anchor::ANCHOR_BOTTOM_RIGHT:
            offset_ = {-size_.x,-size_.y};
            break;
        default:
            break;
    }
}
void node_affiliate::setScale(float scale){
    size_ *= scale;
    setOffsetByAnchor(anchor_);
}